package com.ld.security.server.user.modules.rec.conver;

import com.ld.security.common.core.base.ESuperEntity;
import com.ld.security.common.core.base.column.ListJson;
import com.ld.security.common.core.util.ReflectionUtil;
import com.ld.security.server.user.modules.rec.entity.RecItemEntity;
import com.ld.security.server.user.modules.ups.constant.UpsKeywordConstant;

public class AbstIremConver<E extends ESuperEntity> implements RecItemConver<E> {

    /**
     * 标题
     */
    private String labelField;

    private String contentField;

    private String contentTypeField;

    private String contentCrtUserField;

    private String pictureField="picture";

    public AbstIremConver(String labelField, String contentField, String contentTypeField, String contentCrtUserField,String pictureField) {
        this.labelField = labelField;
        this.contentField = contentField;
        this.contentTypeField = contentTypeField;
        this.contentCrtUserField = contentCrtUserField;
        this.pictureField = pictureField;
    }

    @Override
    public RecItemEntity conver(E e) {
        RecItemEntity itemEntity = new RecItemEntity();

        String label=ReflectionUtil.invokeGetter(e, labelField);
        String content=ReflectionUtil.invokeGetter(e, contentField);

        String picture= ReflectionUtil.invokeGetter(e, pictureField);
        ListJson labelKeys =  this.getKeywordList(label, UpsKeywordConstant.wtType.title.keyNumber);
        ListJson contentKeys =  this.getKeywordList(content, UpsKeywordConstant.wtType.content.keyNumber);

        String contentType = ReflectionUtil.invokeGetter(e,contentTypeField);
        String contentCrtUser = ReflectionUtil.invokeGetter(e,contentCrtUserField);

        itemEntity.setId(e.getId());
//        itemEntity.setLabel(label);
//        itemEntity.setContent(content);
//        itemEntity.setPicture(picture);
        itemEntity.setItemId(e.getId());
        itemEntity.setLabelKeys(labelKeys);
        itemEntity.setContentKeys(contentKeys);
        itemEntity.setContentType(contentType);
        itemEntity.setContentCrtUser(contentCrtUser);


        return itemEntity;
    }
}
